<?php
// APP路径
define('APP_NAME', 'Demo');

require_once dirname(__FILE__) . '/init.php';

/** ---------------- 注册&初始化服务组件 ---------------- **/

// logger
if (IS_SAE) {
	DI()->logger = new Yjnic_Sae_Logger(
		PhalApi_Logger::LOG_LEVEL_DEBUG | PhalApi_Logger::LOG_LEVEL_INFO | PhalApi_Logger::LOG_LEVEL_ERROR
	);
}else{
	DI()->logger = new PhalApi_Logger_File(API_ROOT . '/Runtime/' . APP_NAME, 
    	PhalApi_Logger::LOG_LEVEL_DEBUG | PhalApi_Logger::LOG_LEVEL_INFO | PhalApi_Logger::LOG_LEVEL_ERROR );
}

// curl
DI()->curl = new PhalApi_CUrl();

// 记录访问日志
DI()->logger->debug($_SERVER['REQUEST_URI']);

// cache
DI()->cache = Yjnic_Cache::getCacheIns(DI()->config->get('app.mc_cache'));

// session
DI()->session = new Yjnic_Session(DI()->config->get('app.session'));

//签名服务
DI()->filter = new Yjnic_Filter(DI()->config->get('app.filter'));
/** ---------------- 响应接口请求 ---------------- **/
if (DI()->request->get('service')!=NULL) {
	$api = new PhalApi();
	$rs = $api->response();
	$rs->output();
}else{ //不是服务
	try {
		$route = DI()->request->get('r', 'Index.index');
		Yjnic_Dispatcher::init();
	} catch (Exception $e) {
		header("Content-type: text/html; charset=utf-8");
		echo "网站异常，请联系管理员[".$e->getMessage()."]";die;
	}
}